package cn.tyz.kotlin.ui

import org.jetbrains.anko.*

class SecondActivity : android.support.v7.app.AppCompatActivity() {
    override fun onCreate(savedInstanceState: android.os.Bundle?) {    // ？表示可能为空
        super.onCreate(savedInstanceState)

        val  items = listOf<String>("apple","zhongguo")
        // 1
        verticalLayout {
//            padding = dip(16)     // 可以用
//            paddingTop = dip(16)       // 发现不能用
//            paddingBottom = dip(16)
            verticalPadding = dip(16)   // verticalMargin 同时设置 top 和 bottom
            // 2
            val list = listView() {
                // 3
                adapter = android.widget.ArrayAdapter<String>(this@SecondActivity, android.R.layout.simple_list_item_1, items)
                // 4
                onItemClickListener = object : android.widget.AdapterView.OnItemClickListener {
                    override fun onItemClick(parent: android.widget.AdapterView<*>?, v: android.view.View?, position: Int, id: Long) {
                        when (position) {
                            0 -> {
                                android.widget.Toast.makeText(applicationContext, "kotlin", android.widget.Toast.LENGTH_SHORT).show()
                            }
                            1->{    startActivity<MainActivity>()}
                        }
                    }
                }
            }.lparams(width = org.jetbrains.anko.matchParent) { // 6  lparams来实现类似与xml的 LayoutParams   .lparams { alignParentTop() }
                height = org.jetbrains.anko.wrapContent
            }

            linearLayout {
                button("Login") {
                    textSize = 26f
                }.lparams(width = org.jetbrains.anko.wrapContent) {
                    horizontalMargin = dip(5)
                    topMargin = dip(10)
                }
            }

        }
    }
}

